home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH7 / SRC / OBJ2PICT.CLS < prev    next >
Encoding:
Text File  |  1996-05-04  |  3.2 KB  |  128 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "ObjPicture"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = False
  8. Option Explicit
  9.  
  10. Public Objects As New Collection
  11. Function ObjectType() As String
  12.     ObjectType = "APF PICTURE"
  13. End Function
  14.  
  15.  
  16. ' ************************************************
  17. ' Compute the world coordinate bounds for the
  18. ' picture.
  19. ' ************************************************
  20. Sub Bound(xmin As Single, ymin As Single, xmax As Single, ymax As Single)
  21. Dim x1 As Single
  22. Dim y1 As Single
  23. Dim x2 As Single
  24. Dim y2 As Single
  25. Dim obj As Object
  26. Dim i As Integer
  27.  
  28.     If Objects.Count < 1 Then
  29.         xmin = 0
  30.         xmax = 1
  31.         ymin = 0
  32.         ymax = 1
  33.         Exit Sub
  34.     End If
  35.     
  36.     Set obj = Objects.Item(1)
  37.     obj.Bound xmin, ymin, xmax, ymax
  38.     
  39.     For i = 2 To Objects.Count
  40.         Set obj = Objects.Item(i)
  41.         obj.Bound x1, y1, x2, y2
  42.         If x1 < xmin Then xmin = x1
  43.         If y1 < ymin Then ymin = y1
  44.         If x2 > xmax Then xmax = x2
  45.         If y2 > ymax Then ymax = y2
  46.     Next i
  47. End Sub
  48. ' ************************************************
  49. ' Read the picture from a file using Input.
  50. ' Begin with "PICTURE" to identify this object.
  51. ' ************************************************
  52. Sub FileInput(filenum As Integer)
  53. Dim num As Integer
  54. Dim i As Integer
  55. Dim obj As Object
  56. Dim obj_type As String
  57.  
  58.     ' Read the number of objects in the file.
  59.     Input #filenum, num
  60.     
  61.     ' Repeatedly read objects from the file.
  62.     For i = 1 To num
  63.         Input #filenum, obj_type
  64.         Select Case obj_type
  65.             Case "APF PICTURE"
  66.                 Set obj = New ObjPicture
  67.             Case Else
  68.                 Beep
  69.                 MsgBox "Unknown object type """ & obj_type & """.", , vbExclamation
  70.                 Exit Sub
  71.         End Select
  72.         obj.FileInput filenum
  73.         Objects.Add obj
  74.     Next i
  75. End Sub
  76.  
  77. ' ************************************************
  78. ' Draw the picture on a Form, Printer, or
  79. ' PictureBox.
  80. ' ************************************************
  81. Sub Draw(canvas As Object)
  82. Dim obj As Object
  83.  
  84.     For Each obj In Objects
  85.         obj.Draw canvas
  86.     Next obj
  87. End Sub
  88. ' ************************************************
  89. ' Write the picture to a file using Write.
  90. ' Begin with "APF PICTURE" to identify this object.
  91. ' ************************************************
  92. Sub FileWrite(filenum As Integer)
  93. Dim obj As Object
  94.  
  95.     Write #filenum, "APF PICTURE"
  96.     Write #filenum, Objects.Count
  97.     
  98.     For Each obj In Objects
  99.         obj.FileWrite filenum
  100.     Next obj
  101. End Sub
  102.  
  103. ' ************************************************
  104. ' Apply a nonlinear transformation to the objects.
  105. ' ************************************************
  106. Sub Distort(trans As Object)
  107. Dim obj As Object
  108.  
  109.     For Each obj In Objects
  110.         obj.Distort trans
  111.     Next obj
  112. End Sub
  113.  
  114.  
  115. ' ************************************************
  116. ' Apply a transformation matrix to the objects.
  117. ' ************************************************
  118. Sub Transform(M() As Single)
  119. Dim obj As Object
  120.  
  121.     For Each obj In Objects
  122.         obj.Transform M
  123.     Next obj
  124. End Sub
  125.  
  126.  
  127.  
  128.